<?php
class form_field_dataModel extends baseModel{
    protected $table = 'form_field';

    //字段列表
    public function field_list($fid)
    {
        return $this->select('fid='.$fid.' AND list_display=1','','sequence asc,id asc');
    }

    //表单内容列表
    public function form_list($table_name,$limit,$order,$where=null)
    {
        $this->table='form_data_'.$table_name;
        return $this->select($where,'',$order.',id desc',$limit);
    }

    //表单内容统计
    public function form_count($table_name,$where=null)
    {
        $this->table='form_data_'.$table_name;
        return $this->count($where);
    }

    //添加内容
    public function add($data){
        if(empty($data)){
            return;
        }
        //读取模型表
        $form=model('form')->info($data['fid']);
        //录入表数据
        $this->table='form_data_'.$form['table'];
        $id=$this->insert($data);
        return $id;
    }

    //编辑内容
    public function edit($data){
        if(empty($data)){
            return;
        }
        //读取模型表
        $form=model('form')->info($data['fid']);
        //录入表数据
        $this->table='form_data_'.$form['table'];
        $id=$this->update('id='.$data['id'],$data); 
        return $id;
    }


    //内容信息
    public function info($id,$table_name){
        //读取模型表
        $this->table='form_data_'.$table_name;
        return $this->find('id='.$id);
    }

    //内容删除
    public function del($id,$fid){
        if(empty($id)||empty($fid)){
            return;
        }
        //读取模型表
        $form=model('form')->info($fid);
        //删除操作
        $condition['id']=$id;
        return $this->model->table('form_data_'.$form['table'])->where($condition)->delete();
    }
    
}

?>